export function handleFileUpload(event, fileField, allowedExtensions, context) {
	const file = event.target.files[0];
	if (!validateFileType(file, allowedExtensions)) {
		context.message = `请选择正确的文件格式（.${allowedExtensions.join(', .')}）`;
		setTimeout(() => {
			context.message = '';
		}, 1000);
		event.target.value = '';
		return;
	}
	// 判断文件类型并设置 uploadtype
	const extension = file.name.split('.').pop().toLowerCase();
	if (extension === 'jpg' || extension === 'png') {
		context.uploadtype = 'jpg';
	} else if (extension === 'mp4') {
		context.uploadtype = 'mp4';
	}
	context[fileField] = file;
}

export function validateFileType(file, allowedExtensions) {
	if (!file) return false;
	const extension = file.name.split('.').pop().toLowerCase();
	return allowedExtensions.includes(extension);
}